import axios from 'axios'
import { ElMessage } from 'element-plus'

const baseURL = '/api'
const instance = axios.create({
  baseURL,
  headers: { 'Content-Type': 'application/json' } // 强制JSON格式
})

// 响应拦截器
instance.interceptors.response.use(
  response => response.data,
  error => {
    ElMessage.error(error.response?.data?.message || '服务异常')
    return Promise.reject(error)
  }
)

export default instance